﻿using AutoMapper;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using sixgod.Base.Controllers;
using sixgod.Dtos.User.Search;
using sixgod.Service.User;

namespace sixgod.Module.User.Controllers
{
    [Route("[Controller]")]
    public class UserController:BaseController
    {
        private readonly IUserService _userService;
        private readonly IMapper _mapper;
        public UserController(IUserService userService, IMapper mapper)
        {
            _userService = userService;
            _mapper = mapper;
        }

        #region 查询  

        [HttpGet("pageList")]
        public async Task<IActionResult> GetPageList([FromQuery]UserQueryModel data)
        {
            var result = await _userService.GetPageList(data);
            return Success(result);
        }

        /// <summary>
        /// 下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet("all")]
        public async Task<IActionResult> GetList()
        {
            var result = await _userService.GetAllList();
            return Success(result);
        }

        #endregion

        [HttpPost]
        public async Task<IActionResult> Insert([FromBody]Model.User.User user, [FromServices] ICapPublisher capBus)
        {
            await _userService.InsertAsync(user,capBus);
            return Success();
        }

        [HttpPut]
        public async Task<IActionResult> UpdateUser([FromBody]Model.User.User user, [FromServices] ICapPublisher capBus)
        {
            await _userService.UpdateAsync(user, capBus);
            return Success();
        }

        [HttpDelete("{id}")]
        public async Task<IActionResult> DeleteUser(string id, [FromServices] ICapPublisher capBus)
        {
            await _userService.DeleteAsync(id, capBus);
            return Success();
        }
    }
}
